package com.health.healthproject.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.health.healthproject.dto.ServiceRecordDTO;
import com.health.healthproject.entity.ServiceRecord;
import com.health.healthproject.mapper.ServiceRecordMapper;
import com.health.healthproject.service.ServiceRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ServiceRecordServiceImpl extends ServiceImpl<ServiceRecordMapper, ServiceRecord> implements ServiceRecordService {

    @Autowired
    private ServiceRecordMapper serviceRecordMapper;

    @Override
    public ServiceRecordDTO getServiceRecordWithUserNames(Long id) {
        return serviceRecordMapper.getServiceRecordDetail(id);
    }

   /* @Override
    public IPage<ServiceRecordDTO> pageServiceRecordWithUserNames(Integer pageNum, Integer pageSize, ServiceRecord query) {
        Page<ServiceRecord> page = new Page<>(pageNum, pageSize);
        return serviceRecordMapper.pageServiceRecordList(page, query);
    }*/

    @Override
    @Transactional
    public boolean createServiceRecord(ServiceRecord serviceRecord) {
        return save(serviceRecord);
    }

    @Override
    @Transactional
    public boolean updateServiceRecord(ServiceRecord serviceRecord) {
        return updateById(serviceRecord);
    }

    @Override
    @Transactional
    public boolean deleteServiceRecord(Long id) {
        return removeById(id);
    }

    @Override
    public Page<ServiceRecordDTO> pageServiceRecord(Page<ServiceRecordDTO> page, ServiceRecord query, String startDate, String endDate) {
        return serviceRecordMapper.pageServiceRecordList(page, query,startDate,endDate);
    }
}